package com.huarui.saleOrder.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.ewaf.framework.action.BaseAction;
import org.ewaf.framework.task.Engine;
import org.ewaf.framework.task.Handler;

import com.huarui.params.Params;
import com.huarui.purchaseOrder.model.PurOrSaleOrder;

/**
 * 
 * @author ycf
 *
 */
public class SaleOrderButtonAction extends BaseAction{

	public static final String BUTTONS_STRING = "btns";
	/**
	 * 是否遮盖key
	 */
	public static final String DISCOVER_PARAM = "disa";
	/**
	 * 遮盖
	 */
	public static final String DISCOVER_YES_VALUE = "1";
	/**
	 * 不遮盖
	 */
	public static final String DISCOVER_NO_VALUE = "0";
	
	private static final long serialVersionUID = -6665216827012143782L;

	private Logger logger = Logger.getLogger(SaleOrderButtonAction.class);
	
	private Engine saleOrderButtonEngine;

	private Integer ordersId;
	
	private String status;
	
	private Map<String, Object> btnsMap = new HashMap<String, Object>();
	
	public Integer getOrdersId() {
		return ordersId;
	}

	public void setOrdersId(Integer ordersId) {
		this.ordersId = ordersId;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public Map<String, Object> getBtnsMap() {
		return btnsMap;
	}

	public void setBtnsMap(Map<String, Object> btnsMap) {
		this.btnsMap = btnsMap;
	}

	
	public void setSaleOrderButtonEngine(Engine saleOrderButtonEngine) {
		this.saleOrderButtonEngine = saleOrderButtonEngine;
	}

	private String loadBtns() {
		List<Handler> handlers = saleOrderButtonEngine.getHandlers(status);
		if(handlers == null) {
			handlers = new ArrayList<Handler>();
		}
		
		btnsMap.put(DISCOVER_PARAM, DISCOVER_NO_VALUE);
		if(!PurOrSaleOrder.STATUS_INITIAL.equals(status) && !PurOrSaleOrder.STATUS_TMP.equals(status)
				&& !PurOrSaleOrder.STATUS_WAIT_SELLER_ACPT.equals(status)) {
			btnsMap.put(DISCOVER_PARAM, DISCOVER_YES_VALUE);
		}
		
		btnsMap.put(Params.BUTTON_LIST_PARAM, handlers);
		return BUTTONS_STRING;
	}
	
	public String loadOnlineBtns() {
		
		btnsMap.put(DISCOVER_PARAM, DISCOVER_NO_VALUE);
		if(!PurOrSaleOrder.STATUS_INITIAL.equals(status) && !PurOrSaleOrder.STATUS_TMP.equals(status)
				&& !PurOrSaleOrder.STATUS_WAIT_SELLER_ACPT.equals(status)) {
			btnsMap.put(DISCOVER_PARAM, DISCOVER_YES_VALUE);
		}
		
		status = PurOrSaleOrder.Y + status;
		
		List<Handler> handlers = saleOrderButtonEngine.getHandlers(status);
		if(handlers == null) {
			handlers = new ArrayList<Handler>();
		}
		
		btnsMap.put(Params.BUTTON_LIST_PARAM, handlers);
		return BUTTONS_STRING;
	}
	
	public String loadNotOnlineBtns() {
		
		btnsMap.put(DISCOVER_PARAM, DISCOVER_NO_VALUE);
		if(!PurOrSaleOrder.STATUS_INITIAL.equals(status) && !PurOrSaleOrder.STATUS_TMP.equals(status)
				&& !PurOrSaleOrder.STATUS_WAIT_SELLER_ACPT.equals(status)) {
			btnsMap.put(DISCOVER_PARAM, DISCOVER_YES_VALUE);
		}
		
		status = PurOrSaleOrder.N + status;

		List<Handler> handlers = saleOrderButtonEngine.getHandlers(status);
		if(handlers == null) {
			handlers = new ArrayList<Handler>();
		}
		
		btnsMap.put(Params.BUTTON_LIST_PARAM, handlers);
		return BUTTONS_STRING;
	}
	
}
